window.onload=function(){
    // console.log($('form').serialize());
   
    $('.btn_sub').click(function(){
        var username= $('input[name="username"').val()
        var password=$('input[name="password"').val()
        var userreg=/\d{11}/
        var passreg=/.{6,18}/
        if(userreg.test(username)==false||passreg.test(password)==false){
            layer.msg('用户名或者密码错误,用户名为11位数字，密码需输入6位以上',{
                icon:2,
                time:2000
            })
            return false
        }
        if(!$('.pcheck').prop("checked")){
            layer.msg('请同意协议',{
                icon:2,
                time:2000
            })
            return false
        }

        var loadindex = layer.load(0, {shade: [0.7,'#000']})
        $.post({
            url:'./php/register.php',
            data: {"username":username,"password":password},
            method:"post",
            dataType:'json',
            success:function(res){
                var {meta:{status,msg},data} = res;
                layer.close(loadindex)
                if(status==0){ 
                    layer.msg(msg,{
                        icon:1,
                        time:1500
                    },
                    function(){
                        location.href = "./login.html"
                    })          
                }else{
                    layer.msg(msg,{ 
                        icon:2,
                        time:1500
                    })

                }
            }
        })

        return false
    })
    
    $('.tzsy').click(function(){
        location.href="./home.html"
    })


}